<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="../../assets/css/layui.css">
	<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
	<link rel="stylesheet" type="text/css" href="../../css/add.css"/>
</head>
<body>
<div id="app">
	<div class="header">
		<span>添加用户</span>
	</div>
	<div class="content">
		<table>
			<tr>
				<td class="text-right">用户名</td><td class="content_right"><input id="username" class="input" placeholder="请输入用户名"></td>
			</tr>
			<tr>
				<td class="text-right">手机号码</td><td class="content_right"><input id="userPhone" class="input" placeholder="请输入手机号码"></td>
			</tr>
			<tr>
				<td class="text-right">身份证号码</td><td class="content_right"><input id="idCardNumber" class="input" placeholder="请输入身份证号码"></td>
			</tr>
			<tr>
				<td class="text-right">密码</td><td class="content_right"><input id="password" class="input" placeholder="请输入密码"></td>
			</tr>
			<tr>
				<td></td>
				<td class="content_right">
					<button type="button" class="layui-btn layui-btn-blue" id="submit" >立即提交</button>
					<button type="button" class="layui-btn layui-btn-blue" id="reset" >重置</button>
				</td>
			</tr>
		</table>

	</div>
</div>
</body>
<script src="../../../js/jquery.min.js"></script>
<script src="../../assets/layui.all.js"></script>
<script src="../../../qrcode/jquery2.1.4.js"></script>
<script src="../../../layer/layer.js"></script>
<script src="../../../js/request.js"></script>
<script>
	$(function(){
		$("#reset").click(function(){
			$("input").val("");
		});
		$("#tel").focusout(function(){
			var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
			if(!myreg.test($("#userPhone").val())){
				layer.msg("手机号格式有误,请重新填写")
				$("#tel").val("")
			}
		});
		$("#submit").click(function() {
			if(  $("#username").val().trim()===""||$("#password").val().trim()===""
					||$("#idCardNumber").val().trim()===""||$("#userPhone").val().trim()===""){
				layer.msg("信息缺失，无法提交")
			} else{
				var windowId = layer.load(2);
				var username = $("#username").val();
				var password = $("#password").val();
				var userPhone = $("#userPhone").val();
				var idCardNumber = $("#idCardNumber").val()
				var temp = {username:username, password:password,
					userPhone:userPhone, idCardNumber:idCardNumber}
				temp = JSON.stringify(temp)
				$.ajax({
					type: 'POST',
					url: "/user/insert.do",
					dataType: 'json',
					cache: false,
					headers : {
						'Content-Type' : 'application/json;charset=utf-8'
					},
					// ContentType : 'application/json;charset=utf-8',
					data: temp,
					success: function(data){
						layer.close(windowId);
						if(data==='success'){
							layer.msg("用户添加成功");
						}else if(data==="bound"){
							layer.msg("该手机号已绑定用户");
						}else{
							layer.msg(data.result)
						}
					}
				});
			}
		});
	})
</script>
</html>